<template>
  <div>这是我的页 - action</div>
  <p>count: {{ count }}</p>
  <button @click="fn(1)">异步+1</button>
  <button @click="fn(2)">异步+2</button>
  <button @click="fn(3)">异步+3</button>
</template>

<script>
import { mapState, mapActions } from "vuex";
export default {
  computed: mapState("a", ["count"]),
  // computed: mapState({
  //   count: (state) => state.a.count,
  // }),
  methods: {
    ...mapActions("a", ["incrementAsync"]),
    fn(n) {
      // 用dispatch方法调用actions里面的方法
      // this.$store.dispatch("incrementAsync", { n });
      // this.$store.dispatch({
      //   type: "incrementAsync",
      //   n,
      // });

      this.incrementAsync({ n });
    },
  },
};
</script>
